package com.vtb.thread;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.BlockingQueue;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.vtb.base.VtbBaseReadThread;
import com.vtb.entity.DataCache;
import com.vtb.entity.QqOauth;
import com.vtb.entity.Var;
import com.vtb.servlet.WtbException;

public class QqTraverThread extends VtbBaseReadThread{
	private static final Log log = LogFactory.getLog(QqTraverThread.class);
	public QqTraverThread(BlockingQueue<QqOauth> traver_qqQueue) {
		this.traver_qqQueue = traver_qqQueue;
	}
	public void run() {
	    log.info(Thread.currentThread().getName()+"--已启动");
		HashMap<String,QqOauth> qqMap = DataCache.synCloneMap(QqOauth.class);
		Collection<QqOauth> qqCollection;
		while (qqMap != null) {
			qqCollection = qqMap.values();
			log.debug(Thread.currentThread().getName()+"在工作！");
			for (Iterator<QqOauth> iterator = qqCollection.iterator(); iterator.hasNext();) {
				QqOauth qqOauth =  iterator.next();
				try {
					if (qqOauth.getQ2r().equals(Var.OPEN) || qqOauth.getQ2s().equals(Var.OPEN)) {
						traver_qqQueue.put(qqOauth);
					}
				} catch (InterruptedException e) {
					log.error("放入QQ读取队列失败：", e);
					throw new WtbException("放入QQ读取队列失败", e);
				}
			}
			try {
				log.debug("qq遍历线程在休息！");
				Thread.sleep(1000*60);
			} catch (InterruptedException e) {
				
			}
			qqMap = DataCache.synCloneMap(QqOauth.class);
		}
	}

}
